import { createStore } from 'vuex'
import {getMusicLyric} from '../service/item.js'
import { getPhoneLogin } from '../service/home.js'

export default createStore({
  state: {
    playList: [{
      al: {
        id: 1910054,
        name: "3",
        pic: 109951163208498580,
        picUrl: "https://p1.music.126.net/kVwwq7UTc-yEi6jdGVQkgw==/109951163208498578.jpg",
        pic_str: "109951163208498578"
      },
      // name: "当年情(Live)",

      id: 20515834,
      name:3
    }],
    playListIndex: 0,
    isbtnShow: true, //暂停安钮显示
    detailShow:false,//歌曲详情
    lyricList:{},//歌词
    currentTime:0,//当前时间
    duration:0,//歌曲总时长
    isLogin:false,//是否登录
    isFooterMusic:true,//判断底部组件是否显示
    token:'',
    user:{},
  },
  getters: {
  },
  mutations: {
    updateIsbtnShow: function (state, value) {
      state.isbtnShow = value
    },
    pushPlayList:function(state,value){
      state.playList.push(value)
    },
    updateplayList: function (state, value) {
      state.playList = value
      console.log(state.playList)
    },
    updatePlayListIndex:function(state,value){
      state.playListIndex = value
    },
    updateDetailShow:function(state){
      state.detailShow = !state.detailShow
    },
    updateLyricList:function(state,value){
      state.lyricList=value
    },
    updateCurrentTime:function(state,value){
      state.currentTime = value
    },
    updateDuration:function(state,value){
      state.duration = value
    },
    updateIsLogin:function(state,value){
      state.isLogin = value
    },
    updateToken:function(state,value){
      state.token = value
      localStorage.setItem('token',state.token)
    },
    updateUser:function(state,value){
      state.user = value
      // localStorage.setItem('token',state.token)
    }
  },
  actions: {
    getLyric:async function(context,value){
      let res = await getMusicLyric(value)
      console.log(res)
      context.commit("updateLyricList",res.data.lrc)
    },
    getLogin:async function(context,value){
      let res = await getPhoneLogin(value);
      console.log(res)
      return res
    }
  },
  modules: {
  }
})
